package com.cookor.poi.modules.phy.service;

import com.cookor.poi.common.persistence.DataEntity;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.service.CrudService;
import com.cookor.poi.common.utils.StringUtils;
import com.cookor.poi.modules.phy.dao.FSchedueDao;
import com.cookor.poi.modules.phy.entity.FSchedue;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class FSchedueService extends CrudService<FSchedueDao, FSchedue> {
  public FSchedue get(String id) {
    return (FSchedue)super.get(id);
  }
  
  public List<FSchedue> findList(FSchedue fSchedue) {
    return super.findList( fSchedue);
  }
  
  public Page<FSchedue> findPage(Page<FSchedue> page, FSchedue fSchedue) {
    return super.findPage(page,  fSchedue);
  }
  
  @Transactional(readOnly = false)
  public void save(FSchedue fSchedue) {
    if (StringUtils.isNotBlank(fSchedue.getId())) {
      FSchedue query = (FSchedue)get( fSchedue);
      if (fSchedue.getTotalA() != null && (query.getTotalA() == null || query.getTotalA() != fSchedue.getTotalA()))
        fSchedue.setCountA(Integer.valueOf((fSchedue.getCountA() == null) ? ((fSchedue.getTotalA() == null) ? 0 : fSchedue.getTotalA().intValue()) : (fSchedue.getCountA().intValue() + ((fSchedue.getTotalA() == null) ? 0 : (fSchedue.getTotalA().intValue() - ((query.getTotalA() == null) ? 0 : query.getTotalA().intValue())))))); 
      if (fSchedue.getTotalB() != null && (query.getTotalB() == null || query.getTotalB() != fSchedue.getTotalB()))
        fSchedue.setCountB(Integer.valueOf((fSchedue.getCountB() == null) ? ((fSchedue.getTotalB() == null) ? 0 : fSchedue.getTotalB().intValue()) : (fSchedue.getCountB().intValue() + ((fSchedue.getTotalB() == null) ? 0 : (fSchedue.getTotalB().intValue() - ((query.getTotalB() == null) ? 0 : query.getTotalB().intValue())))))); 
      if (fSchedue.getTotalC() != null && (query.getTotalC() == null || query.getTotalC() != fSchedue.getTotalC()))
        fSchedue.setCountC(Integer.valueOf((fSchedue.getCountC() == null) ? ((fSchedue.getTotalC() == null) ? 0 : fSchedue.getTotalC().intValue()) : (fSchedue.getCountC().intValue() + ((fSchedue.getTotalC() == null) ? 0 : (fSchedue.getTotalC().intValue() - ((query.getTotalC() == null) ? 0 : query.getTotalC().intValue())))))); 
      if (fSchedue.getTotalD() != null && (query.getTotalD() == null || query.getTotalD() != fSchedue.getTotalD()))
        fSchedue.setCountD(Integer.valueOf((fSchedue.getCountD() == null) ? ((fSchedue.getTotalD() == null) ? 0 : fSchedue.getTotalD().intValue()) : (fSchedue.getCountD().intValue() + ((fSchedue.getTotalD() == null) ? 0 : (fSchedue.getTotalD().intValue() - ((query.getTotalD() == null) ? 0 : query.getTotalD().intValue())))))); 
      if (fSchedue.getTotalE() != null && (query.getTotalE() == null || query.getTotalE() != fSchedue.getTotalE()))
        fSchedue.setCountE(Integer.valueOf((fSchedue.getCountE() == null) ? ((fSchedue.getTotalE() == null) ? 0 : fSchedue.getTotalE().intValue()) : (fSchedue.getCountE().intValue() + ((fSchedue.getTotalE() == null) ? 0 : (fSchedue.getTotalE().intValue() - ((query.getTotalE() == null) ? 0 : query.getTotalE().intValue())))))); 
      if (fSchedue.getTotalA() != null && fSchedue.getCountA() != null && fSchedue.getTotalA().intValue() < fSchedue.getCountA().intValue())
        fSchedue.setCountA(fSchedue.getTotalA()); 
      if (fSchedue.getTotalB() != null && fSchedue.getCountB() != null && fSchedue.getTotalB().intValue() < fSchedue.getCountB().intValue())
        fSchedue.setCountB(fSchedue.getTotalB()); 
      if (fSchedue.getTotalC() != null && fSchedue.getCountC() != null && fSchedue.getTotalC().intValue() < fSchedue.getCountC().intValue())
        fSchedue.setCountC(fSchedue.getTotalC()); 
      if (fSchedue.getTotalD() != null && fSchedue.getCountD() != null && fSchedue.getTotalD().intValue() < fSchedue.getCountD().intValue())
        fSchedue.setCountD(fSchedue.getTotalD()); 
      if (fSchedue.getTotalE() != null && fSchedue.getCountE() != null && fSchedue.getTotalE().intValue() < fSchedue.getCountE().intValue())
        fSchedue.setCountE(fSchedue.getTotalE()); 
    } 
    if (fSchedue.getCountA() == null)
      fSchedue.setCountA(fSchedue.getTotalA()); 
    if (fSchedue.getCountB() == null)
      fSchedue.setCountB(fSchedue.getTotalB()); 
    if (fSchedue.getCountC() == null)
      fSchedue.setCountC(fSchedue.getTotalC()); 
    if (fSchedue.getCountD() == null)
      fSchedue.setCountD(fSchedue.getTotalD()); 
    if (fSchedue.getCountE() == null)
      fSchedue.setCountE(fSchedue.getTotalE()); 
    super.save( fSchedue);
  }
  
  @Transactional(readOnly = false)
  public void delete(FSchedue fSchedue) {
    super.delete( fSchedue);
  }
}
